<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">系统管理</a>
        <a>
          <cite>权限管理</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">&#xe666;</i></a>
</div>
<div class="x-body">
    <table class="layui-hide" id="test" lay-filter="test"></table>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add">
                <i class="layui-icon layui-icon-add-circle"></i>添加
            </button>
        </div>
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    </script>
</div>
<script>
    layui.use('table', function(){
        var table = layui.table;
        table.render({
            elem: '#test'
            ,url:'{:url("Admin/menuData")}'
            ,toolbar: '#toolbarDemo'
            ,title: '权限表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true}
                ,{field:'menu_name', title:'权限名称'}
                ,{field:'pid', title:'父级权限'}
                ,{field:'controller', title:'控制器'}
                ,{field:'action', title:'方法'}
                ,{field:'sort', title:'排序'}
                ,{field:'icon', title:'图标',templet:function (d) {
                        return '<i class="layui-icon '+ d.icon +'"></i>';
                    }}
                ,{field:'type', title:'类型',templet:function (d) {
                        if (d.type == 1){
                            return '<span class="layui-btn layui-btn-xs" >菜单</span>';
                        }else {
                            return '<span class="layui-btn layui-btn-xs layui-btn-normal" >按钮</span>';
                        }
                    }}
                ,{field:'status', title:'状态',templet:function (d) {
                        if (d.status == 1){
                            return '<span class="layui-btn layui-btn-xs layui-btn-normal" >正常</span>';
                        }else {
                            return '<span class="layui-btn layui-btn-xs layui-btn-disabled" >禁用</span>';
                        }
                    }}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var event = checkStatus.data;
                    break;
                case 'add':
                    x_admin_show('添加权限','{:url("Admin/menuAdd")}',480,620);
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'del'){
                layer.confirm('真的删除行么', function(index){
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'edit'){
                x_admin_show('修改权限','{:url("Admin/menuEdit")}?id='+data.id,480,620);
            }
        });
    });
</script>
</body>

</html>